package com.qhy.service.imp;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.qhy.mapper.TbQuestionMapper;
import com.qhy.pojo.TbQuestion;
import com.qhy.pojo.TbQuestionExample;
import com.qhy.pojo.TbQuestionExample.Criteria;
import com.qhy.service.IQuestionService;



@Service
public class QuestionService implements IQuestionService {
	
	@Resource
	private TbQuestionMapper mapper; 
	
	
	
	public List<TbQuestion> queryAll() {
		TbQuestionExample  example = new TbQuestionExample();
		example.setOrderByClause("question_father_id");
		return mapper.selectByExample(example);
	}
	
	public List<TbQuestion> query0(){
		TbQuestionExample example = new TbQuestionExample();
		Criteria criteria = example.createCriteria();
		criteria.andQuestionFatherIdEqualTo(0);
		return mapper.selectByExample(example);
	}

	public int addQuestion(TbQuestion question) {
		question.setQuestionDate(new Date());
		if(question.getQuestionFatherId()==0) {
			question.setQuestionName(question.getQuestionOthername());
			question.setQuestionOthername("");
			question.setQuestionAnswe("");
		}
		return mapper.insertSelective(question);
	}

	public int deletequestion(Integer questionId) {
		return mapper.deleteByPrimaryKey(questionId);
	}

	public TbQuestion findById(Integer questionId) {
		return mapper.selectByPrimaryKey(questionId);
	}

	public int updateQuestion(TbQuestion question) {
		if(question.getQuestionFatherId()==0) {
			question.setQuestionName(question.getQuestionOthername());
			question.setQuestionOthername("");
			question.setQuestionAnswe("");
		}
		return mapper.updateByPrimaryKeySelective(question);
	}
	
	
	
	
}
